cmake_minimum_required(VERSION 3.5)

project(algorithm-001 C)

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
set(PREFIX_DIR ${CMAKE_CURRENT_BINARY_DIR}/_prefix)
set(INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR})

option(LOCAL_UTHASH "use local uthash" OFF)

if(NOT LOCAL_UTHASH)
    # import uthash if not installed
    include(ExternalProject)
    ExternalProject_Add(uthash
        PREFIX ${PREFIX_DIR}/uthash
        GIT_REPOSITORY git@github.com:troydhanson/uthash.git
        GIT_TAG "v2.3.0"
        PATCH_COMMAND ""
        UPDATE_COMMAND ""
        CONFIGURE_COMMAND ""
        BUILD_COMMAND ""
        INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory
                ${PREFIX_DIR}/uthash/src/uthash/include
                ${INSTALL_DIR}/include
    )
endif()

set(EXE_NAME algorithm-001)

aux_source_directory(./src SRC)

add_executable(${EXE_NAME} ${SRC})

if(NOT LOCAL_UTHASH)
    target_include_directories(${EXE_NAME} PRIVATE
        ${CMAKE_CURRENT_BINARY_DIR}/include)
endif()